package com.wn.controller;

import com.common.annotation.RequireRoles;
import com.common.entity.PageParam;
import com.common.entity.Requirement;
import com.common.entity.Rsp;
import com.github.pagehelper.PageInfo;
import com.wn.service.RequirementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("requirement")
public class RequirementController {
    /**
     * 服务对象
     */
    @Autowired
    private RequirementService requirementService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Requirement selectOne(String id) {
        return this.requirementService.getOneById(id);
    }

//    @SystemControllerLog(description = "分页查询需求信息")
    @PostMapping("/searchSomeRequirementByPage")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    public Rsp searchSomeByPage(@RequestBody PageParam<Requirement> pageParam, @RequestHeader("token") String token){
        PageInfo<Requirement> requirementPageInfo = requirementService.searchSomeByPage(pageParam);
        return Rsp.success(requirementPageInfo);
    }

//    @SystemControllerLog(description = "添加需求信息")
    @PostMapping("/addOneRequirement")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    public Rsp addOne(@RequestBody @Valid Requirement requirement, @RequestHeader("token") String token){
        System.out.println(requirement);
        return requirementService.addOne(requirement);
    }

//    @SystemControllerLog(description = "逻辑删除需求信息")
    @RequireRoles(roles = {"admin","super_admin","reception"},index = 1)
    @PostMapping("/deleteRequirementLogical")
    public Rsp deleteUserLogical(@RequestBody Requirement requirement,@RequestHeader("token") String token){

        return requirementService.deleteLogical(requirement);
    }


    @RequireRoles(roles = {"admin","super_admin","reception"},index = 1)
    @PostMapping("/updateRequirement")
    public Rsp updateUser(@RequestBody Requirement requirement,@RequestHeader("token") String token){

        return requirementService.update(requirement);
    }
}
